<?php
require_once '../../public/inc/DB.php';
$db = new DB('jusmor_resource');

$action = $_POST['action'];
$return = array('code'=>0, 'msg'=>'');
$now = date('Y-m-d H:i:s');

if($action == 'save_res') {
	$res_file = $_POST['res_file'];
	$size = $_POST['size'];
	$res_name = $_POST['res_name'];
	$source = $_POST['source'];
	
	if(empty($res_file) || empty($res_name) || empty($source)) {
		$return['msg'] = '网络繁忙， 上传失败！';
	}
	
	$data = array('res_file'=>$res_file, 'res_name'=>$res_name, 'source'=>$source, 'size'=>$size, 'create_time'=>$now, 'update_time'=>$now);
	$res = $db->insert($data);
	if(empty($res)) {
		$return['msg'] = '网络繁忙， 上传失败！';
	}
	$return['code'] = 1;
	$return['msg'] = '上传成功！';
	
	echo json_encode($return);
	exit();
}

if($action == 'del_res') {
	$res_id = $_POST['res_id'];
	if(empty($res_id)) {
		$return['msg'] = '网络繁忙， 上传失败！';
	}
	$condition = array('res_id'=>$res_id);
	$res = $db->delete($condition);
	if(empty($res)) {
		$return['msg'] = '网络繁忙， 上传失败！';
	}
	$return['code'] = 1;
	$return['msg'] = '删除成功！';
	
	echo json_encode($return);
	exit();
	
}